package com.warm.quartz.controller;


import cn.dev33.satoken.annotation.SaCheckPermission;
import com.warm.core.domain.AjaxResult;
import com.warm.core.page.BaseController;
import com.warm.core.page.TableDataInfo;
import com.warm.excel.poi.utils.ExcelUtil;
import com.warm.log.annotation.Log;
import com.warm.log.enums.BusinessType;
import com.warm.quartz.service.ISysJobLogService;
import com.warm.select.api.orm.domain.job.SysJobLog;
import org.noear.solon.annotation.*;
import org.noear.solon.core.handle.Context;

import java.util.List;

/**
 * 调度日志操作处理
 *
 * @author hh
 */
@Controller
@Mapping("/monitor/jobLog")
public class SysJobLogController extends BaseController {
    @Inject
    private ISysJobLogService jobLogService;

    /**
     * 查询定时任务调度日志列表
     */
    @SaCheckPermission("monitor:job:list")
    @Get
    @Mapping("/list")
    public TableDataInfo<SysJobLog> list(SysJobLog sysJobLog) {
        return jobLogService.selectJobLogPage(sysJobLog);
    }

    /**
     * 导出定时任务调度日志列表
     */
    @SaCheckPermission("monitor:job:export")
    @Log(title = "任务调度日志" , businessType = BusinessType.EXPORT)
    @Post
    @Mapping("/export")
    public void export(Context ctx, SysJobLog sysJobLog) {
        List<SysJobLog> list = jobLogService.selectJobLogList(sysJobLog);
        ExcelUtil<SysJobLog> util = new ExcelUtil<SysJobLog>(SysJobLog.class);
        util.exportExcel(ctx, list, "调度日志");
    }

    /**
     * 根据调度编号获取详细信息
     */
    @SaCheckPermission("monitor:job:query")
    @Get
    @Mapping(value = "/{jobLogId}")
    public AjaxResult getInfo(Long jobLogId) {
        return success(jobLogService.selectJobLogById(jobLogId));
    }


    /**
     * 删除定时任务调度日志
     */
    @SaCheckPermission("monitor:job:remove")
    @Log(title = "定时任务调度日志" , businessType = BusinessType.DELETE)
    @Delete
    @Mapping("/{jobLogIds}")
    public AjaxResult remove(Long[] jobLogIds) {
        return toAjax(jobLogService.deleteJobLogByIds(jobLogIds));
    }

    /**
     * 清空定时任务调度日志
     */
    @SaCheckPermission("monitor:job:remove")
    @Log(title = "调度日志" , businessType = BusinessType.CLEAN)
    @Delete
    @Mapping("/clean")
    public AjaxResult clean() {
        jobLogService.cleanJobLog();
        return success();
    }
}
